package com.baoyang.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import java.util.Collections;

public class CodeGenerator {
    public static void main(String[] args) {
        FastAutoGenerator.create(
                        "jdbc:mysql://47.115.211.150:3306/baoyang_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai",
                        "baoyang_db","pknhYSyJDkXTdN3m")
                .globalConfig(builder -> {
                    builder.author("金佳军") // 设置作者
                            .outputDir(System.getProperty("user.dir") + "/src/main/java") // 输出路径
                            .disableOpenDir(); // 生成后不自动打开目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.baoyang") // 父包名
                            .entity("entity")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper")
                            .controller("controller")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, System.getProperty("user.dir") + "/src/main/resources/mapper"));
                })
                .strategyConfig(builder -> {
                    builder.addInclude("baoyang_unloading_point") // 需要生成的表
                            .addTablePrefix("baoyang_") // 去除表前缀
                            .entityBuilder().enableLombok()
                            .controllerBuilder().enableRestStyle();
                })
                .templateEngine(new VelocityTemplateEngine()) // 使用Velocity模板引擎
                .execute();
    }
}